package helpers;

import interfaces.State;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class HandleList {
	
	/**
	 * Comparing 2 list<State>
	 * @param list1
	 * @param list2
	 * @return
	 */
	public static boolean compareListState(List<State> list1, List<State> list2)
	{
		if (list1.size() == list2.size())
		{
			return list1.containsAll(list2);
		}
		
		return false;
	}
	
	/**
	 * checking an list state exists or not
	 * @param list
	 * @param subList
	 * @return
	 */
	public static boolean checkExistList(List<List<State>> list, List<State> subList)
	{
		for (List<State> temp: list)
			if (compareListState(temp, subList))
				return true;
		
		return false;
	}
	
	public static boolean checkExistListInMapping(Set<List<State>> list, List<State> subList)
	{
		for (List<State> temp: list)
			if (compareListState(temp, subList))
				return true;
		
		return false;
	}
	
	/**
	 * get state in mapping, use in method convertToDFA
	 * @param mapping
	 * @param input
	 * @return
	 */
	public static State getStateInMapping(Map<List<State>, State> mapping, List<State> input)
	{
		if (mapping.keySet().contains(input))
			return mapping.get(input);
		
		for (Map.Entry<List<State>, State> entry: mapping.entrySet())
			if (compareListState(entry.getKey(), input))
				return entry.getValue();
		
		return null;
	}
}
